CFLAGS = -Wall -std=c99 -lm -fpic -coverage -ftest-coverage -fprofile-arcs

rngs.o: rngs.h rngs.c
	gcc -c rngs.c -g  $(CFLAGS)

dominion.o: dominion.h dominion.c rngs.o
	gcc -c dominion.c -g  $(CFLAGS)

playdom: dominion.o playdom.c
	gcc -o playdom playdom.c -g dominion.o rngs.o $(CFLAGS)

testDrawCard: testDrawCard.c dominion.o rngs.o
	gcc -o testDrawCard -g  testDrawCard.c dominion.o rngs.o $(CFLAGS)

badTestDrawCard: badTestDrawCard.c dominion.o rngs.o
	gcc -o badTestDrawCard -g  badTestDrawCard.c dominion.o rngs.o $(CFLAGS)

testBuyCard: testBuyCard.c dominion.o rngs.o
	gcc -o testBuyCard -g  testBuyCard.c dominion.o rngs.o $(CFLAGS)

testAll: dominion.o testSuite.c
	gcc -o testSuite testSuite.c -g  dominion.o rngs.o $(CFLAGS)

interface.o: interface.h interface.c
	gcc -c interface.c -g  $(CFLAGS)

player: player.c interface.o
	gcc -o player player.c -g  dominion.o rngs.o interface.o $(CFLAGS)

all: playdom player testDrawCard testBuyCard badTestDrawCard unittestresults.out testdominion.out testdominion2.out

clean:
	rm -f feasttest minetest gaincardtest
	rm -f unittest5 unittest6 unittest7 unittest8
	rm -f cardtest5 cardtest6 cardtest7 cardtest8
	rm -f randomtestadventurer2 randomtestcard2 testdominion2
	rm -f *.o playdom.exe playdom test.exe test player player.exe testDrawCard testDrawCard.exe testBuyCard testBuyCard.exe badTestDrawCard badTestDrawCard.exe *.gcov *.gcda *.gcno *.so *.out
	rm -f unittests cardtests unittestresults.out
	rm -f randomtestcard randomtestadventurer randomtestcard.out randomtestadventurer.out
	rm -f testdominion testdominion.out gameResults.out

unittests: unittests.h unittests.c unittest1.c unittest2.c unittest3.c unittest4.c unittest5.c unittest6.c unittest7.c unittest8.c dominion.o rngs.o
	gcc -o unittests -g $^ $(CFLAGS)

cardtests: cardtests.h cardtests.c cardtest1.c cardtest2.c cardtest3.c cardtest4.c cardtest5.c cardtest6.c cardtest7.c cardtest8.c dominion.o rngs.o
	gcc -o cardtests -g $^ $(CFLAGS)

unittestresults.out: unittests cardtests
	./unittests >>  unittestresults.out
	./cardtests >>  unittestresults.out
	gcov -bf dominion.c >> unittestresults.out

flip: clean
	rsync -avz . flip:/tmp/zibolskc_build
	ssh flip -t 'cd /tmp/zibolskc_build && make clean && make all'

randomtestcard: randomtestcard.c dominion.o rngs.o interface.o
	gcc -o $@ -g $^ $(CFLAGS)

randomtestadventurer: randomtestadventurer.c dominion.o rngs.o interface.o
	gcc -o $@ -g $^ $(CFLAGS)

randomtestcard.out: randomtestcard
	rm -f dominion.c.gcov
	./randomtestcard
	gcov -b dominion.c > $@
	sed -n "/1192:    case sea_hag:/,/return 0/p" dominion.c.gcov >> $@

randomtestadventurer.out: randomtestadventurer
	rm -f dominion.c.gcov
	./randomtestadventurer
	gcov -b dominion.c > $@
	sed -n "/int adventurer_effect/,/return 0/p" dominion.c.gcov >> $@

testdominion: testdominion.c dominion.o rngs.o interface.o
	gcc -o $@ -g $^ $(CFLAGS)

testdominion.out: testdominion
	rm -f dominion.c.gcov gameResults.out
	echo "Cleared gameResults.out"
	./testdominion 1 1000
	echo "Ran with 1000 iterations, and a starting seed of 1" > $@
	gcov -b dominion.c >> $@

feasttest: feasttest.c dominion.c dominion.o rngs.o
	gcc -o feasttest feasttest.c dominion.c rngs.c -Wall -fpic -coverage -lm
	./feasttest > feasttest.out
	gcov -bf dominion.gcno >> feasttest.out 2>&1

gaincardtest: gaincardtest.c dominion.c dominion.o rngs.o
	gcc -o gaincardtest gaincardtest.c dominion.c rngs.c -Wall -fpic -coverage -lm
	./gaincardtest > gaincardtest.out
	gcov -bf dominion.gcno >> gaincardtest.out 2>&1

minetest: minetest.c dominion.c dominion.o rngs.o
	gcc -o minetest minetest.c dominion.c rngs.c -Wall -fpic -coverage -lm
	./minetest > minetest.out
	gcov -bf dominion.gcno >> minetest.out 2>&1

randomtestadventurer2: randomtestadventurer2.c dominion.o rngs.o
	gcc -o randomtestadventurer2 -g  randomtestadventurer2.c dominion.o rngs.o $(CFLAGS)

randomtestadventurer2.out: randomtestadventurer2
	./randomtestadventurer2 > randomtestadventurer2.out
	gcov -bf dominion.c >> randomtestadventurer2.out

randomtestcard2: randomtestcard2.c dominion.o rngs.o
	gcc -o randomtestcard2 -g  randomtestcard2.c dominion.o rngs.o $(CFLAGS)

randomtestcard2.out: randomtestcard2
	./randomtestcard2 > randomtestcard2.out
	gcov -bf dominion.c >> randomtestcard2.out

testdominion2: testdominion2.c dominion.o rngs.o
	gcc -o testdominion2 -g  testdominion2.c dominion.o rngs.o $(CFLAGS)

testdominion2.out: testdominion2
	./testdominion2 > testdominion2.out 2> gameresults.out
	gcov -bf dominion.c >> testdominion2.out

test: testDrawCard testBuyCard badTestDrawCard unittestresults.out randomtestcard.out testdominion.out randomtestadventurer2.out testdominion2.out
